package com.andy.wang.controller;

import com.andy.wang.pojo.Chitchat;
import com.andy.wang.pojo.Friend;
import com.andy.wang.pojo.Result;
import com.andy.wang.service.ChitchatService;
import com.andy.wang.service.FriendService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import io.swagger.v3.oas.annotations.Hidden;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@CrossOrigin
@RequestMapping("/FriendChat")
public class FriendController {
    @Autowired
    private FriendService friendService;

    @Autowired
    private ChitchatService chitchatService;

    // 获取好友
    @GetMapping("/friends/{uID}")
    @Operation(summary = "测试Swagger3注解方法Get")
    public Object getFriends(@PathVariable("uID") Long uid) {
        return Result.success(friendService.getFriend(uid));
    }

    // 获取聊天记录
    @GetMapping("/MsgEx/{uID}/{accpID}")
    public Object getFriends(@PathVariable("uID") Long uid, @PathVariable("accpID") Long accpID) {
        LambdaQueryWrapper<Chitchat> friendLambdaQueryWrapper = new LambdaQueryWrapper<Chitchat>();
        friendLambdaQueryWrapper.eq(Chitchat::getUserID, uid)
                .eq(Chitchat::getAcceptID, accpID)
                .or()
                .eq(Chitchat::getUserID, accpID)
                .eq(Chitchat::getAcceptID, uid)
                .orderByAsc(Chitchat::getMessDataTime);

        return Result.success(chitchatService.list(friendLambdaQueryWrapper));
    }
}
